#define  _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>

typedef struct numrepo
{
    int a[2];
}numrepo;
int main()
{
    int index = 0;
    int value = 0;
    numrepo* nums = NULL;

    scanf("%d", &index);
    numrepo* tmp = (numrepo*)malloc(sizeof(numrepo) * index);
    if (tmp == NULL)
    {
        return -1;
    }
    nums = tmp;

    for (int i = 0; i < index; i++)
    {
        scanf("%d %d", nums[i].a, nums[i].a + 1);
    }

    int* arr = NULL;
    int* atmp = (int*)malloc(sizeof(int) * 100000);
    if (atmp == NULL)
    {
        return -1;
    }
    arr = atmp;

    int src = 0;
    int dest = 0;
    int i = 0;
    int j = 0;

    while (src < index)
    {
        if (arr[nums[src].a[i]] != 1)
        {
            if (j == 2)
            {
                j = 0;
                dest++;
            }
            arr[nums[src].a[i]] = 1;
            nums[dest].a[j] = nums[src].a[i];
            j++;
        }
        else
        {
            i++;
            if (i == 2)
            {
                i = 0;
                src++;
            }
        }
    }

    printf("\n\n");
    for (int k = 0; k < dest; k++)
    {
        printf("%d %d\n", nums[k].a[0], nums[k].a[1]);
    }

    if (j != 0)
    {
        printf("%d\n", nums[dest].a[0]);
    }

    return 0;
}

